package vip.kqsy.cloud.blog.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.kqsy.cloud.blog.server.aspect.Aip;
import vip.kqsy.cloud.blog.server.pojo.dto.CommentAddDTO;
import vip.kqsy.cloud.blog.server.pojo.dto.ListCommentDTO;
import vip.kqsy.cloud.blog.server.pojo.vo.ListCommentVO;
import vip.kqsy.cloud.blog.server.service.BlogCommentService;
import vip.kqsy.cloud.core.security.blacklist.BlackList;
import vip.kqsy.cloud.core.security.user.KqsyUserContext;
import vip.kqsy.cloud.core.web.res.R;
import vip.kqsy.cloud.core.web.res.ResPage;

import javax.validation.Valid;

/**
 * <p>
 * 博客评论 前端控制器
 * </p>
 *
 * @author cenjunjie
 * @since 2023-05-03
 */
@RestController
@RequestMapping("/blogComment")
@Api(tags = "评论")
@RequiredArgsConstructor
public class BlogCommentController {

    private final BlogCommentService blogCommentService;

    @PostMapping("add")
    @ApiOperation("添加评论")
    @BlackList
    @Aip("#dto.content")
    public R<Void> add(@Valid CommentAddDTO dto) {
        dto.setUserId(KqsyUserContext.getUser().getId());
        blogCommentService.add(dto);
        return R.ok();
    }

    @GetMapping("list")
    @ApiOperation("评论列表")
    public R<ResPage<ListCommentVO>> list(@Valid ListCommentDTO dto) {
        ResPage<ListCommentVO> list = blogCommentService.list(dto);
        return R.ok(list);
    }

}
